#ifndef STATDB_TB_DEF_HH
#define STATDB_TB_DEF_HH

#include <stdint.h>
#include "config.h"
/* This is DB table definition. There are four value param 
 * which can create a different table. These are TABLE NAME,
 * TABLE COLUMN, get_next table column and get_column_value.
 * In this file, we will realize these four parts, and make it
 * possible to create a identical table.*/

#define MAX_TABLE_NAME_LEN 30
#define MAX_COLUMN_NAME_LEN 30
#define PICA_DB_TABLE
/*All tables will be added in "tables", should 
 * add a relevant table index here. Then initialize 
 * the statdb_tb_info and statdb_tb_column array in 
 * there table defined file.
 */
typedef enum statdb_tb_index{
#ifdef PICA_DB_TABLE
    STATDB_TB_PORTS,
    STATDB_TB_OFFLOWS,
#endif
#ifdef VM_DB_TABLE
    //vm tables may be defined here.
#endif
    STATDB_TB_MAX
}statdb_tb_index_t;

typedef struct statdb_tb_info {
    const char *tb_pfx_name;          //the real table name should be tb_pfx_name##_##TIME
    const char *tb_column_str;        //This is used to create table in sql. Maybe NULL.
    uint32_t column_num;        //number of columns
    bool (*get_tb_next_row)(); //MUST NOT NULL, it used to get next row's value.
    void (*rest_tb_index)();    //
}statdb_tb_info_t;

typedef struct statdb_tb_column{
    const char* name;          //table column name
    int id;                    //used to bind the column in sql_bind func
    const char* type;          //data type of this column used in db.
    bool (*get_column_value)(char *); //get this column value.
} statdb_tb_column_t;

extern statdb_tb_info_t *p_tb_info[STATDB_TB_MAX]; //defined in pica_statdb.cc
extern statdb_tb_column_t *p_tb_column[STATDB_TB_MAX];
#define STATDB_TB_INFO_INIT(index,value) \
    p_tb_info[index] = value;

#define STATDB_TB_ITEM_INIT(index,value) \
    p_tb_column[index] = value;

#define ASSERT_STATDB_TB_INFO_VALID(pinfo)
    //erery column value is not null
    //}

#define ASSERT_STATDB_TB_ITEM_VALID(pinfo) 
    //erery column value is not null
    //}
/*Tables not in "tables" are defined here.*/
//these tables are initialized at startup.
typedef enum statdb_inner_tb_index{
#ifdef PICA_DB_TABLE
    STATDB_INNER_TB_OFFLOW, //_ofFlowCounter table
#endif
    STATDB_INNER_TB_MAX
}statdb_inner_tb_index_t;

//statdb_tb_info_t p_inner_tb_info[STATDB_INNER_TB_MAX];
//statdb_tb_column_t p_inner_tb_column[STATDB_INNER_TB_MAX];

#endif
